﻿<MyControl:SelectableItemControl x:Class="UmlControlLibrary.UmlDiagram"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:MyControl="clr-namespace:UmlControlLibrary"
    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderOptions.CachingHint="Cache">   

    <Control.Resources>

        <!-- ResizeDecorator Template -->
        <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
            <Grid>
                <Rectangle Stroke="Black" StrokeThickness="2" Margin="-3 -3 -3 -3" />
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeNS" Margin="0 -5 0 0"
                       Position="Top"  VerticalAlignment="Top" HorizontalAlignment="Center"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeWE" Margin="-5 0 0 0"
                       Position="Left" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeWE" Margin="0 0 -5 0"
                       Position="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeNS" Margin="0 0 0 -5"
                       Position="Bottom" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-5 -5 0 0"
                       Position="TopLeft" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -5 -5 0"
                       Position="TopRight" VerticalAlignment="Top" HorizontalAlignment="Right"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-5 0 0 -5"
                       Position="BottomLeft" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                <MyControl:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -5 -5"
                       Position="BottomRight" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
            </Grid>
        </ControlTemplate>

        <!-- Draggable Class Template -->
        <!--ControlTemplate x:Key="DragClassTemplate" TargetType="{x:Type Control}">
            <Grid>
                <MyControl:UmlDesignerElement Name="UmlClassView" DataContext="{Binding Path=DataContext}" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="6 6 6 6" />
            </Grid>
        </ControlTemplate-->

        <!-- Draggable Interface Template -->
        <!--ControlTemplate x:Key="DragInterfaceTemplate" TargetType="{x:Type Control}">
            <Grid>
                <MyControl:UmlInterfaceControl Name="UmlInterfaceView" DataContext="{Binding Path=DataContext}" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="6 6 6 6" />
            </Grid>
        </ControlTemplate-->

        <!-- class / interface / enum Item -->
        <ControlTemplate x:Key="DraggableAndResizableDesignerItem" TargetType="MyControl:UmlControl">
            <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" >
                <MyControl:DragThumb Name="DraggableClassView"  /><!--Template="{StaticResource DragClassTemplate}"-->
                <Control Name="resizer" Template="{StaticResource ResizeDecoratorTemplate}" Visibility="Hidden" />
            </Grid>
        </ControlTemplate>

    </Control.Resources>
    <Canvas Background="White" SizeChanged="Canvas_SizeChanged">
        <ScrollViewer Name="ScrollViewer1" Width="500" Height="500" CanContentScroll="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True">
            <Canvas Name="rootCanvas" Width="1000" Height="1000" >
                <Canvas.Background>
                    <VisualBrush TileMode="Tile" Viewport="0,0,40,40" ViewportUnits="Absolute" Viewbox="0,0,40,40"      
ViewboxUnits="Absolute" RenderOptions.CachingHint="Cache">
                        <VisualBrush.Visual>
                            <Canvas>
                                <Rectangle Stroke="#E0E0E0" StrokeThickness="0.25" Width="40" Height="40" Fill="#F9F9F9"  />
                                <Line X1="0" Y1="20" X2="40" Y2="20" Stroke="#808080" StrokeThickness="0.25" />
                                <Line X1="20" Y1="0" X2="20" Y2="40" Stroke="#808080" StrokeThickness="0.25" />
                            </Canvas>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </Canvas.Background>
                <Canvas.LayoutTransform>
                    <ScaleTransform x:Name="uiZoomTransform"
                        ScaleX="{Binding ElementName=uiZoomSlider, Path=Value}" 
                        ScaleY="{Binding ElementName=uiZoomSlider, Path=Value}" />
                </Canvas.LayoutTransform>
                <Button Canvas.Left="99" Canvas.Top="10" Height="22" Name="button1" Width="125" Click="button1_Click">Test create relation</Button>
                <Button Canvas.Left="233" Canvas.Top="10" Height="22" Name="button3" Width="124" Click="button3_Click">Test reroute relation</Button>
            </Canvas>
         </ScrollViewer>
        <Slider Canvas.Left="0" Canvas.Top="2" Height="150" Name="uiZoomSlider" Width="43" Value="1" Maximum="5" Orientation="Vertical" />
    </Canvas>
</MyControl:SelectableItemControl>
